#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5;
int t, n, m, l, V, d[MAXN], v[MAXN], a[MAXN], p[MAXN];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	cin >> t;
	while(t--){
		cin >> n >> m >> l >> V;
		bool A = 1;
		int cnt1 = 0, fir = l;
		for(int i = 1; i <= n; i ++){
			cin >> d[i] >> v[i] >> a[i];
			if(v[i] > V){ 
				fir = min(d[i], fir);
			}
			if(a[i] != 0) A = 0;
		}
		int mx = 0;
		for(int i = 1; i <= m; i ++){
			cin >> p[i];
			mx = max(mx, p[i]);
		}
		if(A){
			for(int i = 1; i <= n; i ++){
				if(d[i] <= mx && v[i] > V) cnt1 ++;
			}
			cout << cnt1 << " " << max(m-cnt1, m-1) << "\n";
		}
		else{
			for(int i = 1; i <= n; i ++){
				
			}
		}
	}
	return 0;
}
